//
//  HHAlertSample.swift
//  HHSwiftuiPractice
//
//  Created by YL-Hong on 2023/10/8.
// Alert

import SwiftUI

struct HHAlertSample: View {
    @State private var showAlert: Bool = false
    @State var name: String = ""
    
    var body: some View {
        ZStack {
            Color.mint
                .edgesIgnoringSafeArea(.all)
            
            Button("添加好友") {
                       name = "李逍遥"
                       showAlert.toggle()
                   }
                   .foregroundColor(Color.black)
                   .padding()
                   .background(Color.yellow)
                   .cornerRadius(15)
                   .alert("Message", isPresented: $showAlert) {
                       Button(role: .cancel) {} label: {
                                  Text("取消")
                              }
                       
                       Button(role: .destructive) {
                           
                       } label: {
                           Text("确定")
                       }

                       
                   } message: {
                       Text("你确定要添加\n\(name)为好友吗？")
                   }
            
        }
        
    }
}

struct HHAlertSample_Previews: PreviewProvider {
    static var previews: some View {
        HHAlertSample()
    }
}
